home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / progs / Netobj / CDK / NetObjectsFusionCDK5_97.exe / _SETUP.1 / RotatingPictureComp.java < prev    next >
Encoding:
Java Source  |  1997-05-14  |  9.0 KB  |  298 lines

  1. import ComponentApp;
  2.  
  3. public class RotatingPictureComp extends ComponentApp
  4. {
  5.     int maxWidth;
  6.     int maxHeight;
  7.     int numImages;
  8.     static final int MaxImages=50;
  9.     DAssetManager assetMan;
  10.     DDrawJava theJavaApplet; 
  11.     int pause;
  12.     int[] imageNames;
  13.     int[] imageURLs;
  14.     
  15.  
  16.     public void onCopy()
  17.     {
  18.         int[] imageNamesOld=imageNames;
  19.         int[] imageURLsOld=imageURLs;
  20.         imageNames=new int[MaxImages];
  21.         imageURLs=new int[MaxImages];
  22.         for(int cnt=0;cnt<numImages;cnt++)
  23.         {
  24.             imageNames[cnt]=imageNamesOld[cnt];
  25.             imageURLs[cnt]=imageURLsOld[cnt];
  26.             if(imageNames[cnt]!=0)
  27.                 assetMan.CopyAsset(imageNames[cnt]);
  28.             if(imageURLs[cnt]!=0)
  29.                 assetMan.CopyAsset(imageURLs[cnt]);
  30.         }
  31.     }
  32.  
  33.  
  34.     public String onInstall(DAssetManager cam, String codeBase) 
  35.     { 
  36.         assetMan = cam;
  37.         return "Rotating Picture";
  38.     }
  39.     
  40.     public void onInspect(CStringArray Names,CStringArray Types)
  41.     {
  42.         Names.Set("Pause Time (Seconds)");
  43.         Types.Set(typeJavaCollection);
  44.         Names.Set("Number of Images");
  45.         Types.Set(typeJavaCollection);
  46.         for(int cnt=0; cnt<numImages; cnt++)
  47.         {
  48.             Names.Set("Image "+Integer.toString(cnt+1));
  49.             Types.Set(typeImage);
  50.             Names.Set("URL for Image "+Integer.toString(cnt+1));
  51.             Types.Set(typeLink);
  52.         }
  53.     }
  54.     
  55.     public String PropertyListener(String Event,String Value,int Get, int propIndex, IDInspector insp) 
  56.     {
  57.         if (Get == 1)
  58.         {
  59.             if (Event.compareTo("Pause Time (Seconds)") == 0)
  60.             {
  61.                 return Integer.toString(pause);
  62.             }
  63.             else if (Event.compareTo("Number of Images") == 0)
  64.             {
  65.                 return Integer.toString(numImages);
  66.             }
  67.             else
  68.             {
  69.                 for(int cnt=0; cnt<numImages; cnt++)
  70.                 {
  71.                     if (Event.compareTo("Image "+Integer.toString(cnt+1))==0)
  72.                         return Integer.toString(imageNames[cnt]);
  73.                     if (Event.compareTo("URL for Image "+Integer.toString(cnt+1))==0)
  74.                         return Integer.toString(imageURLs[cnt]);
  75.                 }
  76.             }
  77.         }
  78.         else
  79.         {
  80.             if (Event.compareTo("Pause Time (Seconds)") == 0)
  81.             {
  82.                 pause=Integer.parseInt(Value,10);
  83.                 if(pause<1)
  84.                     pause=1;
  85.                 theJavaApplet.AddParam("Pause Time",typeString,Integer.toString(pause));                                
  86.             }
  87.             else if (Event.compareTo("Number of Images") == 0)
  88.             {
  89.                 int newNumImages=Integer.parseInt(Value,10);
  90.                 if(newNumImages>MaxImages)
  91.                     newNumImages=MaxImages;
  92.                 if(newNumImages<numImages)
  93.                 {
  94.                     DImage imageSizer=new DImage();
  95.                     maxHeight=maxWidth=0;
  96.                     for(int iter=0;iter<newNumImages;iter++)
  97.                     {
  98.                         String theImageFile=assetMan.GetAssetLocation(imageNames[iter], IAssetContext.Preview, IFileNameStyle.DosName);
  99.                         imageSizer.setImageFile(theImageFile);
  100.                         IDSize currentImageSize=imageSizer.getSize();
  101.                         if(currentImageSize.getHeight()>maxHeight)
  102.                         {
  103.                             maxHeight=currentImageSize.getHeight();
  104.                         }
  105.                         if(currentImageSize.getWidth()>maxWidth)
  106.                         {
  107.                             maxWidth=currentImageSize.getWidth();
  108.                         }
  109.                     }
  110.                     theJavaApplet.SetSize(maxWidth, maxHeight);
  111.                 }
  112.                 while(newNumImages<numImages)
  113.                 {
  114.                     assetMan.RemoveAsset(imageNames[--numImages]);
  115.                 }
  116.                 numImages=newNumImages;
  117.                 theJavaApplet.AddParam(Event,typeString,Value);                                
  118.             }
  119.             else 
  120.             {
  121.                 for(int cnt=0; cnt<numImages; cnt++)
  122.                 {
  123.                     if (Event.compareTo("Image "+Integer.toString(cnt+1))==0)
  124.                     {    
  125.                         if(imageNames[cnt]!=0)
  126.                         {
  127.                             assetMan.RemoveAsset(imageNames[cnt]);
  128.                         }
  129.                         imageNames[cnt]=Integer.parseInt(Value,10);
  130.                         String theImageFile=assetMan.GetAssetLocation(imageNames[cnt], IAssetContext.Preview, IFileNameStyle.DosName);
  131.                         theJavaApplet.setImageFile(theImageFile);
  132.                         DImage imageSizer=new DImage();
  133.                         maxHeight=maxWidth=0;
  134.                         for(int iter=0;iter<numImages;iter++)
  135.                         {
  136.                             theImageFile=assetMan.GetAssetLocation(imageNames[iter], IAssetContext.Preview, IFileNameStyle.DosName);
  137.                             imageSizer.setImageFile(theImageFile);
  138.                             IDSize currentImageSize=imageSizer.getSize();
  139.                             if(currentImageSize.getHeight()>maxHeight)
  140.                             {
  141.                                 maxHeight=currentImageSize.getHeight();
  142.                             }
  143.                             if(currentImageSize.getWidth()>maxWidth)
  144.                             {
  145.                                 maxWidth=currentImageSize.getWidth();
  146.                             }
  147.                         }
  148.                         theJavaApplet.SetSize(maxWidth, maxHeight);
  149.                     }
  150.                     if (Event.compareTo("URL for Image "+Integer.toString(cnt+1))==0)
  151.                         imageURLs[cnt]=Integer.parseInt(Value,10);;
  152.                 }
  153.             }    
  154.         }
  155.         return "";
  156.     }
  157.     
  158.     
  159.     public void onDrop(IDLayout layout, IDRect r, int fDrop) 
  160.     {
  161.         if (fDrop != ActivateState.Drop)  // the first time the component is dropped
  162.             return;
  163.         
  164.         numImages=3;
  165.         int xPos;
  166.         int yPos;
  167.         
  168.         int cnt;
  169.         pause=2;
  170.         imageNames=new int[MaxImages];
  171.         imageURLs=new int[MaxImages];
  172.         for(cnt=0;cnt<MaxImages;cnt++)
  173.         {
  174.             imageURLs[cnt]=0;
  175.             imageNames[cnt] = 0;
  176.         }
  177.         theJavaApplet = new DDrawJava();
  178.         theJavaApplet.setImageFile(theJavaApplet.getCodeBase() + "banner.gif");
  179.         theJavaApplet.setAppletFileName(theJavaApplet.getCodeBase() + "RotatingPicture.class");                
  180.         theJavaApplet.setStretch(PictureStretchMode.DRAW_NATURAL);
  181.         theJavaApplet.setAltTag("Rotating Picture");
  182.         xPos=r.getLeft();
  183.         yPos=r.getTop();
  184.         layout.AddObject(theJavaApplet);
  185.  
  186.         theJavaApplet.AddParam("Pause Time",typeString,"2");                                
  187.         theJavaApplet.AddParam("Number of Images",typeString,"3");                                
  188.         imageNames[0] = assetMan.AddAsset(theJavaApplet.getCodeBase()+"banner.gif",IAssetType.Image,"");    
  189.         imageNames[1] = assetMan.AddAsset(theJavaApplet.getCodeBase()+"banner2.gif",IAssetType.Image,"");    
  190.         imageNames[2] = assetMan.AddAsset(theJavaApplet.getCodeBase()+"banner3.gif",IAssetType.Image,"");    
  191.         DImage imageSizer=new DImage();
  192.         imageSizer.setImageFile(theJavaApplet.getCodeBase() + "banner.gif");
  193.         IDSize currentImageSize=imageSizer.getSize();
  194.         if(currentImageSize.getHeight()>maxHeight)
  195.         {
  196.             maxHeight=currentImageSize.getHeight();
  197.             if(currentImageSize.getWidth()>maxWidth)
  198.                 maxWidth=currentImageSize.getWidth();
  199.             theJavaApplet.SetPositionRect(xPos, yPos, xPos+maxWidth, yPos+maxHeight);
  200.         }
  201.         else if(currentImageSize.getWidth()>maxWidth)
  202.         {
  203.             maxWidth=currentImageSize.getWidth();
  204.             theJavaApplet.SetPositionRect(xPos, yPos, xPos+maxWidth, yPos+maxHeight);
  205.         }
  206.     }
  207.     
  208.     public void onUnInstall(DAssetManager cam) 
  209.     {
  210.         
  211.     }
  212.     
  213.     protected void finalize() 
  214.     {
  215.         for(int cnt=0;cnt<numImages;cnt++)
  216.         {
  217.             if(imageNames[cnt]!=0)
  218.                 assetMan.RemoveAsset(imageNames[cnt]);
  219.         }
  220.     }
  221.     
  222.     public void onPublish(DAssetManager asm, int context)
  223.     {
  224.         if(context==IAssetContext.Preview)
  225.         {
  226.             for(int cnt=0;cnt<numImages;cnt++)
  227.             {
  228.                 String theLoc=assetMan.GetAssetLocation(imageNames[cnt],context, IFileNameStyle.HTMLName);
  229.                 theLoc.replace('|',':');
  230.                 theJavaApplet.AddParam("Image "+Integer.toString(cnt+1),typeString,"file:///"+theLoc);
  231.             }
  232.         }
  233.         else
  234.         {
  235.             for(int cnt=0;cnt<numImages;cnt++)
  236.             {
  237.                 theJavaApplet.AddParam("Image "+Integer.toString(cnt+1),typeString,assetMan.GetAssetRelativeLocation(imageNames[cnt],context, 0));                                
  238.             }
  239.         }
  240.         for(int cnt=0;cnt<numImages;cnt++)
  241.         {
  242.             String theURL;
  243.             if(imageURLs[cnt]!=0)
  244.             {
  245.                 theURL=assetMan.GetAssetLocation(imageURLs[cnt], context, IFileNameStyle.DosName);
  246.             }
  247.             else
  248.             {
  249.                 theURL="";
  250.             }
  251.             theJavaApplet.AddParam("URL for Image "+Integer.toString(cnt+1),typeString,theURL);                                
  252.         }
  253.         theJavaApplet.AddParam("Image Width",typeString,Integer.toString(maxWidth));
  254.         theJavaApplet.AddParam("Image Height",typeString,Integer.toString(maxHeight));
  255.         
  256.         
  257.         IDRect thePosition=theJavaApplet.getObjectRect();
  258.         theJavaApplet.AddParam("X Position",typeString,Integer.toString(thePosition.getLeft()));
  259.         theJavaApplet.AddParam("Y Position",typeString,Integer.toString(thePosition.getTop()+7));
  260.         
  261.         
  262.         IDLayout layout = theJavaApplet.getLayout();
  263.         IDSite site  = layout.getSite();
  264.         IDStyle style = site.getCurrentStyle();        
  265.         
  266.         int backgroundStyle = layout.getBackgroundStyle();
  267.         
  268.         if (backgroundStyle != BackgroundStyle.None)
  269.         {
  270.             if (backgroundStyle == BackgroundStyle.SolidColor)
  271.                 theJavaApplet.AddParam("BackgroundColor",typeString,Integer.toString(layout.getBackgroundColor()));
  272.             else if (backgroundStyle == BackgroundStyle.Image)
  273.             {
  274.                 int backID = assetMan.AddAsset(layout.getBackgroundImage(),IAssetType.Image,"");        
  275.                 String theParam=assetMan.GetAssetRelativeLocation(backID,context,1);
  276.                 if(context == IAssetContext.Preview)
  277.                     theParam="file:///"+theParam;
  278.                 theJavaApplet.AddParam("BackgroundImage",typeString,theParam);
  279.             }
  280.         }
  281.         else
  282.         {        
  283.             backgroundStyle = style.getBackgroundStyle();
  284.             
  285.             if (backgroundStyle == BackgroundStyle.SolidColor)
  286.                 theJavaApplet.AddParam("BackgroundColor",typeString,Integer.toString(style.getBackgroundColor()));
  287.             else if (backgroundStyle == BackgroundStyle.Image)
  288.             {
  289.                 int backID = assetMan.AddAsset(style.getBackgroundImage(),IAssetType.Image,"");        
  290.                 String theParam=assetMan.GetAssetRelativeLocation(backID,context,1);
  291.                 if(context == IAssetContext.Preview)
  292.                     theParam="file:///"+theParam;
  293.                 theJavaApplet.AddParam("BackgroundImage",typeString,theParam);
  294.             }
  295.         }
  296.     }
  297. }
  298.